package com.spzx.product.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spzx.domain.Brand;
import com.spzx.product.service.IBrandService;
import com.spzx.vo.Result;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "品牌管理")
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private IBrandService brandService;

    /**
     * 新增品牌
     */
    @PostMapping
    @Schema(description = "新增品牌")
    public Result addBrand(Brand brand){
        int code = brandService.addBrand(brand);
        return Result.build(null,code,"新增品牌成功");
    }

    /**
     * 修改品牌
     */
    @PutMapping
    @Schema(description = "修改品牌")
    public Result updateBrand(Brand brand){
        brandService.updateById(brand);
        return Result.build(null,200,"修改品牌成功");
    }

    /**
     *  获取品牌详细信息
     */
    @GetMapping("/{id}")
    @Schema(description = "获取品牌详细信息")
    public Result<Brand> getBrandById(@PathVariable Long id){
        return Result.build(brandService.getById(id),200,"获取品牌详细信息成功");
    }

    /**
     * 查询品牌分页
     */
    @GetMapping("/list/{page}/{size}")
    @Schema(description = "查询品牌分页")
    public Result<Page<Brand>> getBrandList(@PathVariable Integer page, @PathVariable Integer size){
        return Result.build(brandService.getBrandList(page,size),200,"查询品牌分页成功");
    }

    /**
     * 删除品牌
     */
    @DeleteMapping("/{id}")
    @Schema(description = "删除品牌")
    public Result deleteBrand(@PathVariable Long id){
        brandService.removeById(id);
        return Result.build(null,200,"删除品牌成功");
    }

}
